package mercurius.fitness.client.rb.diet.forms;

import com.google.gwt.user.client.rpc.AsyncCallback;

import mercurius.fitness.client.locale.Locale;
import mercurius.fitness.client.rb.diet.Diet;
import mercurius.fitness.client.rb.diet.DietRB;
import net.pleso.framework.client.bl.forms.IEditForm;
import net.pleso.framework.client.bl.forms.items.IFormItem;
import net.pleso.framework.client.bl.forms.items.IFormItemsGroup;
import net.pleso.framework.client.bl.forms.items.impl.EditFormItem;
import net.pleso.framework.client.bl.forms.items.impl.FormItemsGroup;
import net.pleso.framework.client.bl.forms.items.impl.MultilineEditFormItem;
import net.pleso.framework.client.dal.IDataRow;

public class EditDietForm extends DietForm implements IEditForm {

	private Integer id = null;
	private String type = "";
	
	public EditDietForm(Integer id,String type) {
			this.id = id;
			this.type = type;
	}
	
	public void updateRow(IDataRow row, AsyncCallback callback) {
		DietRB.getDataSet().update((Diet) row, callback,type); 
	}

	public void GetData(AsyncCallback callback) {
		DietRB.getDataSet().get(this.id, callback,type);
	}

	public String getCaption() {
		return Locale.constants().edit_diet_caption();
	}

	public IFormItemsGroup[] getGroups() {
		if(type.equals(Diet.TYPE_LOG)) {
			return groups_log;
		} else if(type.equals(Diet.TYPE_MASTER_REPOSITORY) || type.equals(Diet.TYPE_PRIVATE_REPOSITORY)) {
			return groups_nutrition;
		}
		return null;  // It should never reach here.
	}
}
